#!/usr/bin/env python
from astropy.table import Table
import numpy as np

tab = Table.read("persist_result.tab",format='ipac')
x = tab['x'].data
channel = np.zeros(len(x)-3)
for i in range(len(x)-3):
    if x[i]<4314:
        channel[i] = 1
    else:
        channel[i] = 2
chan = np.append(channel.astype(int),np.array([-99,-99,-99]))
tab['channel'] = chan
tab.write("persist_result.tab",format='ipac',overwrite=True)
print("persist_c01",np.mean(abs(tab['flux'][chan==1])),np.max(abs(tab['flux'][chan==1])))
print("persist_c02",np.mean(abs(tab['flux'][chan==2])),np.max(abs(tab['flux'][chan==2])))
